using System;
using System.Web.UI;
using NuSoft.Business;
using NuSoft.Business.Framework;

namespace NSFxSamples.Entity_Finder
{
	public partial class Default : Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			BindWithEntityFinder();

			BindWithPredicate();
		}


		// Find all Departments where GroupName = "Executive General and Administration"
		private void BindWithEntityFinder()
		{
			EntityFinder finder = new EntityFinder("GroupName", "Executive General and Administration");

			gvDepartments.DataSource = Department.GetDepartments().FindEntities(finder);
			gvDepartments.DataBind();
		}


		// Find all Departments where GroupName contains "Research" and ModifiedDate is after February 7, 1982
		private void BindWithPredicate()
		{
			EntityList<Department> depts = Department.GetDepartments();
			EntityList<Department> filteredDepts = new EntityList<Department>();
			depts.FindAll(filteredDepts, IsResearchDepartment);

			gvDepartments2.DataSource = filteredDepts;
			gvDepartments2.DataBind();
		}


		private static bool IsResearchDepartment(Department dept)
		{
			return (dept.GroupName.Contains("Research") && dept.ModifiedDate > new DateTime(1982, 2, 7));
		}
	}
}